package com.hornsun.client.common.api;

import com.hornsun.client.common.dto.HtmlDTO;
import com.hornsun.repository.FavouriteRepository;
import com.hornsun.repository.InformationRepository;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by 编译中... on 2018/5/10.
 */
@RestController
@RequestMapping("/api/html")
public class HtmlAPI {

    @Resource
    private InformationRepository informationRepository;

    @Resource
    private FavouriteRepository favouriteRepository;

    @GetMapping("/getContent")
    public ResponseEntity<HtmlDTO> getContent(HttpServletRequest httpRequest, @RequestParam("guid")String guid){
        String openid = httpRequest.getAttribute("openid").toString();
        HtmlDTO htmlDTO = new HtmlDTO();
        htmlDTO.setCheckFavourite(favouriteRepository.checkFavourite(openid,guid));
        htmlDTO.setInformation(informationRepository.getInformationByGuid(guid));
        return new ResponseEntity<HtmlDTO>(htmlDTO, HttpStatus.OK);
    }


}
